package com.longsunhd.yum.buffalo.base;

import android.annotation.SuppressLint;
import android.app.Application;
import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

import com.longsunhd.yum.buffalo.util.AppStateTracker;
import com.longsunhd.yum.buffalo.util.ToastUtils;
import com.longsunhd.yum.buffalo.widget.SimplexToast;

import cat.ereza.customactivityoncrash.CustomActivityOnCrash;


public class BaseApplication extends Application {
    private static BaseApplication mInstance;
    static Context _context;
    @Override
    public void onCreate() {
        super.onCreate();
        mInstance=this;
        _context = getApplicationContext();
        ToastUtils.init(this);
        AppStateTracker.track(this, new AppStateTracker.AppStateChangeListener() {
            @Override
            public void appTurnIntoForeground() {
                // 处理app到前台的逻辑
                System.err.println("-----------------------------------上电");
                //如果不是pda对象则不会触发上下电
//                GlobalClient.getClient().hdPowerOn();
            }

            @Override
            public void appTurnIntoBackGround() {
                // app处理到到后台的逻辑
                System.err.println("-----------------------------------下电");
//                GlobalClient.getClient().hdPowerOff();


            }
        });
        CustomActivityOnCrash.install(_context);
    }
    public static Context getInstance() {
        return mInstance;
    }
    public static void showToast(int message) {
        showToast(message, Toast.LENGTH_LONG, 0);
    }

    public static void showToast(String message) {
        showToast(message, Toast.LENGTH_LONG, 0, Gravity.BOTTOM);
    }

    public static void showToast(int message, int icon) {
        showToast(message, Toast.LENGTH_LONG, icon);
    }

    public static void showToast(String message, int icon) {
        showToast(message, Toast.LENGTH_LONG, icon, Gravity.BOTTOM);
    }

    public static void showToastShort(int message) {
        showToast(message, Toast.LENGTH_SHORT, 0);
    }

    public static void showToastShort(String message) {
        showToast(message, Toast.LENGTH_SHORT, 0, Gravity.BOTTOM);
    }

    public static void showToastShort(int message, Object... args) {
        showToast(message, Toast.LENGTH_SHORT, 0, Gravity.BOTTOM, args);
    }

    public static void showToast(int message, int duration, int icon) {
        showToast(message, duration, icon, Gravity.BOTTOM);
    }

    public static void showToast(int message, int duration, int icon,
                                 int gravity) {
        showToast(_context.getString(message), duration, icon, gravity);
    }

    public static void showToast(int message, int duration, int icon,
                                 int gravity, Object... args) {
        showToast(_context.getString(message, args), duration, icon, gravity);
    }

    public static void showToast(String message, int duration, int icon, int gravity) {
        Context context = _context;
        if (context != null)
            SimplexToast.show(context, message, gravity, duration);
    }


}
